package pl.edu.agh.gronoMining.frequentSubgraphFinder.graph.simpleGraph;

import java.util.HashSet;
import java.util.Set;

import pl.edu.agh.gronoMining.frequentSubgraphFinder.graph.Edge;
import pl.edu.agh.gronoMining.frequentSubgraphFinder.graph.GraphException;
import pl.edu.agh.gronoMining.frequentSubgraphFinder.graph.Node;

public class SimpleNode implements Node{

	private int id;
	private int label;
	private int type;
	
	private Set<Edge> edges = new HashSet<Edge>();
	
	public SimpleNode(int id, int label, int type) {
		this.id = id;
		this.label = label;
		this.type = type;
	}

	public int getId() {
		return id;
	}

	public int getLabel() {
		return label;
	}

	public int getType() {
		return type;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setLabel(int label) {
		this.label = label;
	}

	public void setType(int type) {
		this.type = type;
	}
	
	public Set<Edge> getEdges() {
		return edges;
	}
	
	public void addEdge(Edge edge) throws GraphException {
		if (edges.contains(edge))
			throw new GraphException("Edge egsists");
		edges.add(edge);
	}
	
	public Edge addEdgeToNode(Node node, int edgeLabel) throws GraphException {
		Edge edge = new SimpleEdge(edgeLabel, this, node);
		edge.checkIntegraty();
		return edge;
	}
	
	public Edge getEdgeToNode(Node node) {
		for (Edge e : edges) {
			if (e.getOtherNode(this).getId() == node.getId()) {
				return e;
			}
		}
		return null;
	}
	
	public void removeEdge(Edge edge) {
		this.edges.remove(edge);
	}
	
	public String toString() {
		return "Node - id="+id+", label="+label+", type="+type;
	}
	
	public boolean equals(Object o) {
		Node node = (Node) o;
		if (node.getId() == id)
			return true;
		return false;
	}
	
	public int hashCode() {
		return new Integer(id).hashCode();
	}
	
	public Node copy(int newId) {
		return new SimpleNode(newId, label, type);
	}
}
